#include "mainscence.h"
#include "ui_mainscence.h"
#include <QAction>
#include <QPainter>
#include "mypushbutton.h"
#include "chooselevelscene.h"
#include <QTimer>
#include <QSound>
#include <QThread>

MainScence::MainScence(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScence)
{
    ui->setupUi(this);
    this->setFixedSize(QSize(460,780));
    this->setWindowIcon(QIcon(":/res/MenuSceneBg.png"));
    this->setWindowTitle("一起来翻金币");
    connect(ui->actionexit,&QAction::triggered,this,[=](){
        this->close();
    });
    //add costom button
    MyPushButton* beginbtn =  new MyPushButton(":/res/MenuSceneStartButton.png");
    beginbtn->setParent(this);
    beginbtn->move(this->width()*0.5 - beginbtn->width()*0.5,this->height()*0.7);
    //选关场景
    ChooseLevelScene* choose = new ChooseLevelScene(this);
    QSound * s = new QSound(":/res/TapButtonSound.wav",this);

    //开始按钮连接信号
    connect(beginbtn,&QPushButton::clicked,[=](){
        //音效
        s->play();
        beginbtn->zoomup();
        beginbtn->zoomdown();

        QTimer::singleShot(200,[=](){
            this->hide();
            choose->setGeometry(this->geometry());
            choose->show();
        });



    });
    //connect(chose,&QWidget::on)
}

MainScence::~MainScence()
{
    delete ui;
}
void MainScence::paintEvent(QPaintEvent* ev)
{
    //创建画家
    QPainter painter(this);
    //创建QPixmap对象
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(), pix);
    //加载标题
    pix.load(":/res/Title.png");
    //缩放图片
    pix = pix.scaled(pix.width()*0.5,pix.height()*0.5);
    //画出标题图片
    painter.drawPixmap(10,30,pix.width(),pix.height(),pix);

}
void MainScence::initChoseScene(ChooseLevelScene *choose)
{
    //choose->resize(this->width(),this->height());
    //
}

















































